package com.zsyh.jiujiu.dialog;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.example.zyh.toolslib.utils.EmptyUtil;
import com.zsyh.jiujiu.R;
import com.zsyh.jiujiu.utils.StatusUtil;
import com.zsyh.jiujiu.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * @ProjectName: livvehelp
 * @Package: com.zsyh.lsb.ui
 * @ClassName:
 * @Description: java类作用描述
 * @Author: zsyh
 * @CreateDate: 2020/9/7 11:59
 * @UpdateUser: liangwanbo
 * @UpdateDate: 2020/9/7 11:59
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class TianXieDialog extends DialogFragment implements ClallBackData {


    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.desc)
    EditText desc;
    @BindView(R.id.cancle)
    TextView cancle;
    @BindView(R.id.sure)
    TextView sure;
    private Unbinder unbinder;
    private ClallBackData clallBackData;
    private String title;

    public TianXieDialog(String title){
        this.title=title;
    }


    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_xinxi, container, false);
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        unbinder = ButterKnife.bind(this, view);
        name.setText(title);
        return view;
    }

    public void setSelectAddresFinish(ClallBackData clallBackData) {
        this.clallBackData = clallBackData;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onStart() {
        super.onStart();
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        getDialog().getWindow().setLayout(dm.widthPixels, dm.heightPixels - StatusUtil.getStatusBarHeight(getActivity()));
    }


    @Override
    public void getData(String data, String name, String number) {

    }

    @OnClick({R.id.cancle, R.id.sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cancle:
                dismiss();
                break;
            case R.id.sure:
                if(EmptyUtil.isEmpty(desc.getText().toString())){
                    ToastUtils.showShort(getActivity(),"内容不能为空");
                    return;
                }
                clallBackData.getData(desc.getText().toString(),"","");
                dismiss();
                break;
        }
    }
}
